from django.db import models
from login.models import User


# Create your models here.

class Corp(models.Model):
    """旅游公司模型"""
    name = models.CharField(max_length=255, verbose_name='公司名')
    owner = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_corp', verbose_name='所有者')

    class Meta:
        db_table = 'corp'
        verbose_name = verbose_name_plural = '旅游公司'

    def __str__(self):
        return self.name


class TourBooking(models.Model):
    """旅游订单"""
    guests = models.ManyToManyField(User, verbose_name='顾客', related_name='user_tour_bookings')
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name='价格')
    corp = models.ForeignKey(Corp, on_delete=models.CASCADE, related_name='corp_tour_bookings', verbose_name='所在公司')

    class Meta:
        db_table = 'tour_booking'
        verbose_name = verbose_name_plural = '旅游订单'

    def __str__(self):
        return 'TourBooking ' + str(self.id)


class Trip(models.Model):
    """行程模型"""
    booking = models.ForeignKey(TourBooking, on_delete=models.CASCADE, related_name='booking_trips',
                                verbose_name='所属订单')
    date_start = models.DateField(verbose_name='开始时间')
    date_end = models.DateField(verbose_name='结束时间')
    attraction = models.CharField(max_length=255, verbose_name='景点')

    class Meta:
        db_table = 'trip'
        verbose_name = verbose_name_plural = '行程'

    def __str__(self):
        return 'Trip ' + str(self.id) + ', ' + self.attraction
